package com.happy.study.util;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class ResultBody<T> implements Serializable {

    private ResultBody () {

    }

    /**
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success () {
        ResultBody resultBody = new ResultBody ();
        resultBody.code = StateEnum.SUCCESS.getCode ();
        resultBody.message = StateEnum.SUCCESS.getMessage ();
        return resultBody;
    }

    /**
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success ( Object object ) {
        ResultBody resultBody = new ResultBody ();
        resultBody.code = StateEnum.SUCCESS.getCode ();
        resultBody.message = StateEnum.SUCCESS.getMessage ();
        resultBody.count = 1;
        resultBody.data = object;
        return resultBody;
    }

    /**
     * 增加集合对象
     *
     * @param queryList
     * @return
     */
    public static ResultBody success ( List queryList, int count ) {
        ResultBody resultBody = new ResultBody ();
        resultBody.code = StateEnum.SUCCESS.getCode ();
        resultBody.message = StateEnum.SUCCESS.getMessage ();
        resultBody.count = count;
        resultBody.data = queryList;
        return resultBody;
    }

    /**
     * @param pageNum    : 页码
     * @param pageSize   : 每页数量
     * @param queryList  : 返回数据
     * @Author: Wuzh
     * @Description: 成功方法
     * @Data:
     */
    public static ResultBody success ( int pageNum, int pageSize, int count, List queryList ) {
        ResultBody resultBody = new ResultBody ();
        resultBody.count = count;
        resultBody.pageNum = pageNum;
        resultBody.pageSize = pageSize;
        resultBody.code = StateEnum.SUCCESS.getCode ();
        resultBody.message = StateEnum.SUCCESS.getMessage ();
        resultBody.data = queryList;
        return resultBody;
    }

    /**
     * @param code    : 返回状态码
     * @param message : 返回信息
     * @Author: Wuzh
     * @Description: 异常执行失败方法
     * @Data:
     */
    public static ResultBody fail ( String code, String message ) {
        ResultBody resultBody = new ResultBody ();
        resultBody.code = code;
        resultBody.message = message;
        return resultBody;
    }

    /**
     * 重载异常方法
     * @param stateEnum
     * @return
     */
    public static ResultBody fail ( StateEnum stateEnum ) {
        ResultBody resultBody = new ResultBody ();
        resultBody.code = stateEnum.getCode ();
        resultBody.message = stateEnum.getMessage ();
        return resultBody;
    }

    /**
     * 查询得到的数据列表
     */
    private Object data;

    /**
     * 查询总记录数
     */
    private int count;

    /**
     * 页码
     */
    private int pageNum;

    /**
     * 每页条数
     */
    private int pageSize = 10;

    /**
     * 结果编码，000000表示查询成功
     */
    private String code;

    /**
     * 结果信息
     **/
    private String message;

}
